/*
 * @Description: 路由配置
 * @Author: hai-27
 * @Date: 2020-02-07 16:23:00
 * @LastEditors: hai-27
 * @LastEditTime: 2020-02-27 13:58:48
 */
import Vue from 'vue'
import Router from 'vue-router'
import Home from '../views/Home'
import Error from '../components/Error.vue'
import Housekeeping from '../views/HouseKeeping'
import About from '../views/About'
import Goods from '../views/Goods'
import Details from '../views/Details'
import ShoppingCart from '../views/ShoppingCart'
import Collect from '../views/Collect'
import Order from '../views/Order'
import ConfirmOrder from '../views/ConfirmOrder'
import SubScribe from '../views/SubScribe'
import User from '../views/User'
import Tab1 from '../views/SubScribe/Tab1'
import Tab2 from '../views/SubScribe/Tab2'
import Tab3 from '../views/SubScribe/Tab3'
import Tab4 from '../views/SubScribe/Tab4'
import Tab5 from '../views/SubScribe/Tab5'
import Tab6 from '../views/SubScribe/Tab6'
import Tab7 from '../views/SubScribe/Tab7'
import Tab8 from '../views/SubScribe/Tab8'
import Tab9 from '../views/SubScribe/Tab9'
import Tab10 from '../views/SubScribe/Tab10'

Vue.use(Router)

const routes = [

  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/error',
    name: 'Error',
    component: Error
  },
  {
    path: '/housekeeping',
    name: 'Housekeeping',
    component: Housekeeping
  },
  {
    path: '/goods',
    name: 'Goods',
    component: Goods
  },
  {
    path: '/about',
    name: 'About',
    component: About
  },
  {
    path: '/goods/details',
    name: 'Details',
    component: Details
  },
  {
    path: '/shoppingCart',
    name: 'ShoppingCart',
    component: ShoppingCart,
    meta: {
      requireAuth: true // 需要验证登录状态
    }
  },
  {
    path: '/collect',
    name: 'Collect',
    component: Collect,
    meta: {
      requireAuth: true // 需要验证登录状态
    }
  },
  {
    path: '/order',
    name: 'Order',
    component: Order,
    meta: {
      requireAuth: true // 需要验证登录状态
    }
  },
  {
    path: '/user',
    name: 'user',
    component: User,
    meta: {
      requireAuth: true // 需要验证登录状态
    }
  },
  {
    path: '/confirmOrder',
    name: 'ConfirmOrder',
    component: ConfirmOrder,
    meta: {
      requireAuth: true // 需要验证登录状态
    },
  },
  {
    path: '/subscribe',
    name: 'SubScribe',
    component: SubScribe,
    children: [
      {
        path: '/subscribetab1',
        component:Tab1
      },
      {
        path: '/subscribetab2',
        component: Tab2
      },
      {
        path: '/subscribetab3',
        component: Tab3
      },
      {
        path: '/subscribetab4',
        component: Tab4
      },
      {
        path: '/subscribetab5',
        component: Tab5
      },
      {
        path: '/subscribetab6',
        component: Tab6
      },
      {
        path: '/subscribetab7',
        component: Tab7
      },
      {
        path: '/subscribetab8',
        component: Tab8
      },
      {
        path: '/subscribetab9',
        component: Tab9
      },
      {
        path: '/subscribetab10',
        component: Tab10
      },
    ],
    // meta: {
    //   requireAuth: true // 需要验证登录状态
    // },
  }
]

const router = new Router({
  // base: '/dist',
  // mode: 'history',
  routes
})

/* 由于Vue-router在3.1之后把$router.push()方法改为了Promise。所以假如没有回调函数，错误信息就会交给全局的路由错误处理。
vue-router先报了一个Uncaught(in promise)的错误(因为push没加回调) ，然后再点击路由的时候才会触发NavigationDuplicated的错误(路由出现的错误，全局错误处理打印了出来)。*/
// 禁止全局路由错误处理打印
const originalPush = Router.prototype.push;
Router.prototype.push = function push (location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}

export default router
